package com.example.kotlincustomview.ui

import android.support.v4.content.ContextCompat
import android.view.View
import android.widget.Toast
import com.example.kotlincustomview.R
import com.example.kotlincustomview.act_base.BaseActivity
import com.example.kotlincustomview.ui.adapter.WritingBoardAdapter
import kotlinx.android.synthetic.main.act_writing_layout.*
import java.lang.Exception

class WritingBoardActivity : BaseActivity() {
    var mWritingBoardAdapter: WritingBoardAdapter? = null
    override fun attachLayoutRes(): Int {
        return R.layout.act_writing_layout
    }

    override fun initView() {
        mWritingBoardAdapter = WritingBoardAdapter()
        setView(view1, R.color.colorPrimary)
        setView(view2, R.color.color_ff0000)
        setView(view3, R.color.color_00ffff)
        setView(view4, R.color.color_009944)
        setView(view5, R.color.color_8957a1)
        setView(view6, R.color.color_00479d)

        setBgView(bg_view1, R.color.color_ff556170)
        setBgView(bg_view2, R.color.color_ffd6ab)
        setBgView(bg_view3, R.color.color_ffc7ab)
        setBgView(bg_view4, R.color.color_ababff)
        setBgView(bg_view5, R.color.color_ffabcb)
        setBgView(bg_view6, R.color.color_b3ffab)
        mButton1?.setOnClickListener {
            mLinePathView?.clear()
        }
        mButton?.setOnClickListener {
            if (mLinePathView.touched) {
                Toast.makeText(this@WritingBoardActivity, "暂未实现，请等待", Toast.LENGTH_SHORT).show()
//                try {
//                    var imageNmae = "12132132131.png"
//                    mLinePathView.save(imageNmae, true, 10)
//                } catch (e: Exception) {
//                    e.printStackTrace()
//                    Toast.makeText(this@WritingBoardActivity, "保存失敗", Toast.LENGTH_SHORT).show()
//                }
            }
        }

    }

    fun setView(view1: View?, int: Int) {
        view1?.setOnClickListener {
            mLinePathView?.setPenColor(ContextCompat.getColor(this@WritingBoardActivity, int))
        }
    }

    fun setBgView(view1: View?, int: Int) {
        view1?.setOnClickListener {
            mLinePathView?.setBackColor(ContextCompat.getColor(this@WritingBoardActivity, int))

        }
    }
}